// pages/store-info/store-info.js
import request from '../../utils/request'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    url:'',
    label:'',
    address:'',
    storeName:'',
    phone:'',
    latitude:'',
    longitude:'',
    active:0,
    week:['周一','周二','周三','周四','周五','周六','周日'],
    weeks:['周一','周二','周三','周四','周五','周六','周日'],
    date: [],
    details:'',
    courseList:[]
  },
  changeAct(e){
    this.setData({
      active:e.target.dataset.id
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options);
    this.getCourseList()
    this.getDate()
    this.setDate()
    this.getweek()
    this.getStoreInfo(options.id)
  },
  getDate(AddDayCount){
    var dd = new Date();
    dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期
    var m = dd.getMonth()+1;//获取当前月份的日期
    var d = dd.getDate();
    return m+"-"+d;
  },
  getweek(i){
    let today = new Date();
    let weekdays = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
    let nextDay = new Date(today.getTime() + 24 * 60 * 60 * 1000 * i);
    return weekdays[nextDay.getDay()]
  },
  setDate(){
    this.setData({
      date:[{week:'今天',Date:this.getDate(0)},
            {week:this.getweek(1),Date:this.getDate(1)},
            {week:this.getweek(2),Date:this.getDate(2)},
            {week:this.getweek(3),Date:this.getDate(3)},
            {week:this.getweek(4),Date:this.getDate(4)},
            {week:this.getweek(5),Date:this.getDate(5)},
            {week:this.getweek(6),Date:this.getDate(6)}]
    })
  },
  showSheet(){
    wx.showActionSheet({
      itemList: ['呼叫 010-89250780','复制号码'],
      success(res){
        console.log(res.tapIndex);
        if(res.tapIndex == 1){
          wx.showToast({
            title: '已成功复制',
          })
        }
      },
      fail(res){
        console.log(res.errMsg);
      }
    })
  },
openMap(){
  wx.openLocation({
    latitude: this.data.latitude ,
    longitude: this.data.longitude,
    address: this.data.address,
    name:this.data.storeName,
    success: (res) => {console.log(666);},
    fail: (res) => {console.log(111);}
  })
},
getStoreInfo(id){
  request({
    url:'/store/info/'+id  
  }).then(res=>{
    if(res.code === 200){
      const {address,latitude,longitude,phone,storeName,thumbnail,label,details} = res.data
      this.setData({
        details,
        address,
        label,
        url:thumbnail,
        storeName,
        phone,
        latitude,
        longitude
      })
    }else{
      console.log(res.message);
    }
  }).catch(rea=>{
    console.log(rea);
  })
},
getCourseList(){
  request({
    url:'/course/list'
  }).then(res=>{
    console.log(res);
    if(res.code === 200){
      this.setData({
        courseList:res.data
      })
    }
  }).catch(err=>{
    console.log(err);
  })
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})